﻿@using KPIS.GERP.Models.ICM
@model KPIS.GERP.Models.ICM.Dispense
@{
    ViewBag.Title = "จ่ายพัสดุ [DP]";
    ViewBag.Descr = "เพิ่มรายการจ่าย";
   
}

@using (Html.BeginForm("Create", "Dispense", FormMethod.Post, new { id="form", @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above">
        @Html.ButtonViewAll()
        @Html.ButtonSubmit()
    </div>
    
    //@Html.ValidationSummary(true, KPIS.GERP.Models.Class.ValidateText.RequiredField, new { @class = "alert alert-error" })
    @Html.Partial("_EditorForm")

}

@section scripts
{
    <script>
       
        $('.date-picker').datepicker({ language: 'th-th', format: 'dd/mm/yyyy' });

        $("form").not("#formsearch").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm("ท่านต้องการยืนยัน ใช่หรือไม่", function (result) {
                if (result) {

                    var Date = $("#txtDispenseDate").val();
                    var Parcel = $("#ddlRequestParcel option:selected").val();
                    var Name = $("#txtName").val();
 
                    if (Parcel == 0 || Date == "" || Name == "") {
                        if (Parcel == 0) { $("#lblReqParcel").show(); } else { $("#lblReqParcel").hide(); }
                        if (Date == "") { $("#lblDispenseDate").show(); } else { $("#lblDispenseDate").hide(); }
                        if (Name == "") { $("#lblName").show(); } else { $("#lblName").hide(); }
                    }
                    else {
                        currentForm.submit();
                    }
                }
            });
        });

        // getJSON to รายการขอเบิก
        function FetchRequestParcel() {            
            var Request = $("#ddlRequestParcel").val();
            $.getJSON('@Url.Action("GetRequestParcel", "Dispense")' + "/" + Request, null, function (data) {
                $("#txtName").val(data.ReqName);
                $("#txtReqBy").val(data.ReqBy);
                $("#txtWarehouse").val(data.Warehouse);
                $("#txtJobSite").val(data.JobSite);
                $("#txtProject").val(data.Project);

                $("#hdReqById").val(data.ReqById);
                $("#hdWhId").val(data.WarehouseId);
                $("#hdJobSiteId").val(data.JobSiteId);
                $("#hdProjectId").val(data.ProjectId);
                $("#hdApprovedBy").val(data.ApproveBy);
                $("#hdApprovedWhen").val(data.ApproveWhen);

            });

            // Reset TextBox
            if ($("#ddlRequestParcel option:selected").val() == 0) {
                $("#txtName").val("");
                $("#txtReqBy").val("");
                $("#txtWarehouse").val("");
                $("#txtJobSite").val("");
                $("#txtProject").val("");

                $("#hdReqById").val("");
                $("#hdWhId").val("");
                $("#hdJobSiteId").val("");
                $("#hdProjectId").val("");
            }
        }


    </script>
}